package com.nf.health.app.main_intervention.activity;

import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nf.health.app.Constants;
import com.nf.health.app.R;
import com.nf.health.app.activity.global.BaseActivity;
import com.nf.health.app.glide.GlideUtil;
import com.nf.health.app.http.Act;
import com.nf.health.app.main_intervention.bean.MySportBean;
import com.nf.health.app.utils.ViewUtil;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 执行方案： 运动
 * @author yuyahao
 */
public class RunActivity extends BaseActivity{
    private String ID  ="";
    @Bind(R.id.tv_suggest_tip_run)
    TextView tv_suggest_tip_run;

    @Bind(R.id.tv_suggest_time_run)
    TextView tv_suggest_time_run;
    @Bind(R.id.iv_show_img_run)
    ImageView iv_show_img_run;
    @Bind(R.id.tv_of_iv_type)//运动类型
    TextView tv_of_iv_type;
    @Bind(R.id.tv_su_run_title)//有氧运动标题
    TextView tv_su_run_title;
    @Bind(R.id.tv_time_for_runright)//有氧运动时间
    TextView tv_time_for_runright;
    @Bind(R.id.tv_run_for_du)//有氧运动强度
    TextView tv_run_for_du;
    @Bind(R.id.tv_su_decail_run)//有氧运动具体详情
    TextView tv_su_decail_run;
    @Bind(R.id.tv_su_funtion)//有氧运动具体详情
     TextView tv_su_funtion;
    @Bind(R.id.tv_su_title)//建议标题
    TextView tv_su_title;
   @Bind(R.id.tv_su_decail)//建议具体详情
    TextView tv_su_decail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitleBar(R.layout.titlebar_base);
        setContent(R.layout.activity_run_take);
        ButterKnife.bind(this);
        ViewUtil.setText(this, R.id.titlebar_title_tv, "执行方案");
        initListener();
        initView();
    }

    private void initView() {
        String  strtv_suggest_time_run = "建议时间：9:30 上午";
        tv_suggest_time_run.setText(TextUtils.isEmpty(strtv_suggest_time_run) ? "" :strtv_suggest_time_run );
        String  strtv_tv_of_iv_type = "-太极拳八卦-";
        tv_of_iv_type.setText(TextUtils.isEmpty(strtv_tv_of_iv_type) ? "" :strtv_tv_of_iv_type );

        String  strtv_tv_su_run_title = "有氧运动";
        tv_su_run_title.setText(TextUtils.isEmpty(strtv_tv_su_run_title) ? "" :strtv_tv_su_run_title );
        String  str_tv_time_for_runright = "30分钟";
        tv_time_for_runright.setText(TextUtils.isEmpty(str_tv_time_for_runright) ? "" :str_tv_time_for_runright );
        String  str_tv_run_for_du = "运动的心率控制在104-114次/分钟";
        tv_run_for_du.setText(TextUtils.isEmpty(str_tv_run_for_du) ? "" :str_tv_run_for_du );

        StringBuilder strtv_su_decail_run = new StringBuilder();
        strtv_su_decail_run.append("<font color='#2E86F4'>"  +"1."+ "</font>"+ "增加呼吸系统，改善生活黄精,多多运动吧，加油"+"<br>");
        strtv_su_decail_run.append("<font color='#2E86F4'>"  +"2."+ "</font>"+ "增加呼吸系统，改善生活黄精,多多运动吧，加油"+"<br>");
        strtv_su_decail_run.append("<font color='#2E86F4'>"  +"3."+ "</font>"+ "增加呼吸系统，改善生活黄精,多多运动吧，加油"+"<br>");
        strtv_su_decail_run.append("<font color='#2E86F4'>"  +"4."+ "</font>"+ "增加呼吸系统，改善生活黄精,多多运动吧，加油"+"<br>");
       /* tv_su_decail_run.setText(TextUtils.isEmpty(strtv_su_decail_run) ? "" :Html.fromHtml(strtv_su_decail_run.toString()) );
        tv_su_decail_run.setMovementMethod(LinkMovementMethod.getInstance());*/

        String  str_tv_su_decail_run = "建议";
        tv_su_title.setText(TextUtils.isEmpty(str_tv_su_decail_run) ? "" :str_tv_su_decail_run );
        String  strtv_tv_suggest_time_run = "";
        tv_su_decail.setText(TextUtils.isEmpty(strtv_tv_suggest_time_run) ? "" :strtv_tv_suggest_time_run );
       // JustifyTextView justifyTextView;
        GlideUtil.loadNetImg2(RunActivity.this,iv_show_img_run,"",R.drawable.default_image);
        ID =getIntent().getStringExtra(Constants.INTERVENTION_ID);
    }

    private void initListener() {

    }
    @Override
    protected void onResume() {
        super.onResume();
        loadData(ID);
    }
   private void loadData(String id){
        provider.getInterveneSportById(id);
   }
    @Override
    public void handleActionSuccess(String actionName, Object object) {
        super.handleActionSuccess(actionName, object);
        switch (actionName){
            case Act.Flag.GETINTERVENESPORTBYID_FLAG:
                MySportBean mySportBean  = (MySportBean) object;
                if(mySportBean != null){
                    tv_suggest_time_run.setText(TextUtils.isEmpty(mySportBean.getTime()) ? "建议时间：暂无" : "建议时间：" +mySportBean.getTime()+" "+mySportBean.getHour());
                    GlideUtil.loadNetImg(RunActivity.this,iv_show_img_run,mySportBean.getPicture(),R.drawable.default_image);
                    tv_of_iv_type.setText(TextUtils.isEmpty(mySportBean.getName()) ? "" : mySportBean.getName());
                    tv_time_for_runright.setText(TextUtils.isEmpty(mySportBean.getSporttime()) ? "" : mySportBean.getSporttime());
                    tv_run_for_du.setText(TextUtils.isEmpty(mySportBean.getSportstrength()) ? "" : mySportBean.getSportstrength());
                    String StrS =TextUtils.isEmpty(mySportBean.getEffect()) ? "" : mySportBean.getEffect();
                    if(StrS.contains("||")){
                        String result [] = StrS.split("\\|\\|");
                        StringBuilder sb = new StringBuilder();
                        for(int i = 0 ; i < result.length; i++){
                            sb.append("<font color='#2E86F4'>"  +(i+1)+"."+ "</font>"+ result[i]+"<br>");
                        }
                        tv_su_decail_run.setText(TextUtils.isEmpty(sb) ? "" :Html.fromHtml(sb.toString()) );
                        tv_su_decail_run.setMovementMethod(LinkMovementMethod.getInstance());
                    }else{
                        if(!TextUtils.isEmpty(StrS)){
                            tv_su_decail_run.setText(StrS);
                            tv_su_decail_run.setVisibility(View.VISIBLE);
                            tv_su_funtion.setVisibility(View.VISIBLE);
                        }else{
                            tv_su_decail_run.setVisibility(View.GONE);
                            tv_su_funtion.setVisibility(View.GONE);
                        }


                    }

                    if(TextUtils.isEmpty(mySportBean.getSuggest())){
                        tv_su_decail.setVisibility(View.GONE);
                        tv_su_title.setVisibility(View.GONE);
                    }else{
                        tv_su_decail.setVisibility(View.VISIBLE);
                        tv_su_title.setVisibility(View.VISIBLE);
                        tv_su_decail.setText(mySportBean.getSuggest());
                    }

                }

                break;
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.aaa:
                break;
        }
    }
}
